using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using IBM.Data.DB2.iSeries;


namespace ImprCheques
{
    class accesoDatos400
    {
        private iDB2DataAdapter da = new iDB2DataAdapter();
        private iDB2Connection cn = new iDB2Connection();
        private iDB2Command cm = new iDB2Command();
        private string connectionString = "DataSource=192.168.22.56;DefaultCollection=CPXDATOS;UserID=transfer;Password=transfer";

        public accesoDatos400() {
            cn.ConnectionString = connectionString;
        }

        public int ejecutarSQL(string sqlStr) {
            int numReg;
            cn.Open();
            cm.Connection = cn;
            cm.CommandText = sqlStr;
            numReg = cm.ExecuteNonQuery();
            cn.Close();
            return numReg;
        }

        public DataTable leerDatosSQL(string sqlStr) {
            DataTable dt = new DataTable();
            cn.Open();
            cm.Connection = cn;
            cm.CommandText = sqlStr;
            da.SelectCommand = cm;
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public string leerValorSQL(string sqlStr)
        {
            string tValor;
            object tCampo;
            cn.Open();
            cm.Connection = cn;
            cm.CommandText = sqlStr;

            tCampo = cm.ExecuteScalar();
            if (tCampo == null)
            {
                tValor = "";
            }
            else
            {
                tValor = tCampo.ToString();
            }

            cn.Close();
            return tValor;
        }
    }
}
